-- @owner: @taoying
-- @date: 2025-09-17
-- @testpoint: object_id函数触发器测试，部分合理报错
-- @modify: 

--step1:连接兼容D库创建数据库
@conn PrimaryDbDmode;
--step2:删除插件
create extension if not exists shark;
--step3:执行测试
DROP TABLE if exists user_log;
CREATE TABLE user_log (
id SERIAL PRIMARY KEY,
username VARCHAR(50),
email VARCHAR(100),
action_type VARCHAR(10),
action_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE OR REPLACE FUNCTION log_user_actions()
RETURNS TRIGGER AS $$
BEGIN
IF TG_OP = 'INSERT' THEN
INSERT INTO user_log (username, email, action_type)
VALUES (NEW.username, NEW.email, 'INSERT');
RETURN NEW;
ELSIF TG_OP = 'UPDATE' THEN
INSERT INTO user_log (username, email, action_type)
VALUES (NEW.username, NEW.email, 'UPDATE');
RETURN NEW;
ELSIF TG_OP = 'DELETE' THEN
INSERT INTO user_log (username, email, action_type)
VALUES (OLD.username, OLD.email, 'DELETE');
RETURN OLD;
END IF;
END;
$$ LANGUAGE plpgsql;
/

CREATE TRIGGER users_trigger 
AFTER INSERT OR UPDATE OR DELETE ON user_log 
FOR EACH ROW 
EXECUTE FUNCTION log_user_actions();
/

Select object_id('test.sys.users_trigger');
Select object_id('users_trigger', 'TR');
Select object_id('sys.users_trigger');
Select object_id(,'TR');
Select object_id('TR');
Select object_id('users_trigger');
Select object_id('user_log','TR');
--step4:清理环境
drop TABLE if exists user_log;
drop TRIGGER if exists users_trigger on user_log;
drop FUNCTION if exists log_user_actions;